package com.situ.controller;

import com.situ.bean.Cart;

import com.situ.bean.User;
import com.situ.service.impl.CartService;
import com.situ.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class DeleteCartController {

    @Autowired
    private CartService cartService;

    // 添加商品到购物车


    // 更新购物车中商品的数量

    // 删除购物车中的某个商品
    @DeleteMapping("/remove/{productId}/{userId}")
    public String deleteCartItem(@PathVariable int userId, @PathVariable int productId) {
        cartService.deleteCartItem(userId, productId);
        return "商品已从购物车中删除";
    }

    // 清空某个用户的购物车
    @DeleteMapping("/clear")
    public String clearCart(HttpSession session) {
        cartService.clearCart( ((User) session.getAttribute(SYS.UPLOAD_USER)).getId());
        return "购物车已清空";
    }
}